package com.ssh.web.caction;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class StaffLogoutAction extends ActionSupport implements SessionAware {

	/**
	 *
	 */

	private static final long serialVersionUID = 1L;
	// For SessionAware
	private Map<String, Object> session;

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return logout();
	}

	/**
	 * @return the session
	 */
	public Map<String, Object> getSession() {
		return session;
	}

	public String logout() {
		/* STAFFID和PASSWORD为空则返回登录页面，否则验证登录 */
		try {
			session = ActionContext.getContext().getSession();
			String staffId = (String) session.get("staffId");
			String password = (String) session.get("password");
			String permission = (String) session.get("permission");
			System.out.println("staffId=" + staffId + "password=" + password
					+ "permission=" + permission);
			ActionContext.getContext().getSession().remove(session);
		} catch (Exception e) {
			return "login";
		}
		return "login";
	}

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}

}
